import service from '@/utils/request'
import {ElMessage} from "element-plus/es";

// 查询业务系统
export const getWorkSysApi = () => {
    return service.get('/meta/getSysMeta')
}
// 根据系统查询表名
export const getTableNameApi = (syscode: string) => {
    return service.get(`/meta/getSysTable?syscode=${syscode}`)
}
// 根据表名查询对应的字段名
export const getSysTableFieldApi = (tablename: string) => {
    return service.get(`/meta/getSysTableField?tablename=${tablename}`)
}
// 保存
export const savaScriptApi = (data: Object) => {
    return service.post(`/meta/savaScriptApi`, data)
}

export const getTableInfoApi = () => {
    return service.get(`/meta/getTableInfo`)
}



export async function useTableFieldApi(tableName: string | number) {
    if (tableName == null) {
        ElMessage.error("表名不能为空！");
        return;
    }
    const res = await service({
        url: '/gen/table/field/',
        method: "GET",
        params: {
            table: tableName
        }
    })
    return res
}

export async function useGrnCodeAPI(tableName: string | number) {
    const res = await service({
        url: '/gen/table/create',
        method: "GET",
        params: {tableJson: "{table:{name:hr_salary_data,child:[{table:{name:hr_salary_data_details}}]}}"}
        // params: tableJson

    })
    return res
}

export async function useGeneratorAPI(tableName: string | number) {
    if (tableName == null) {
        ElMessage.error("表名不能为空！");
        return;
    }
    const res = await service({
        url: '/gen/table/genCode',
        method: "GET",
        params: {table: tableName}
        // params: {table: "{table:{name:hr_salary_data,child:({table:{name:hr_salary_data_details}})}}"}

    })
    return res
}

export async function usegetSalaryDataAggAPI(tableName: string | number) {

    const res = await service({
        url: '/salary/getSalaryDataAgg',
        method: "GET",
        // params: {   table: tableName    }
        params: {table: "{'table':{'name':'HR_SALARY_DATA','child':[{'table':{'name':'HR_SALARY_DATA_DETAILS'}}]}}"}
    })
    return res
}

export async function useupdSalaryDataAggAPI(tableName: string | number) {

    const res = await service({
        url: '/salary/updSalaryData',
        method: "POST",
        // params: {   table: tableName    }
        params: {table: "{'table':{'name':'HR_SALARY_DATA','child':[{'table':{'name':'HR_SALARY_DATA_DETAILS'}}]}}"}
    })
    return res
}

export async function usedelSalaryDataAPI(tableName: string | number) {

    const res = await service({
        url: '/salary/delSalaryDataAgg',
        method: "POST",
        // params: {   table: tableName    }
        params: {table: "{classpatch:com.xisoft.devise.entity.salary.SalaryDataEntity,id:1111,2222}"}
    })
    return res
}
